package org.sdfc.model.attr

import com.documentum.fc.common.IDfId
import com.documentum.fc.common.IDfTime

import org.sdfc.model.MutableTypedObject
import org.sdfc.model.TypedObject

/** An attribute single of the data model.
 */
trait SingleAttribute[+T] extends Attribute[T] {
  
  /** AttrType of the Attribute, refined to be a SingleAttrType. */
  override def attrType : SingleAttrType[T]
  
  /** False, by definition of this. */
  final def isRepeating = false
  
  
  /** The generic form for this, refined to be of the single kind. */
  val genericForm : SingleAttributeGenericForm[T]
  
}


/** An attribute single/boolean of the data model.
 */
trait SingleBooleanAttribute extends SingleAttribute[Boolean] {
  attr =>
  
  /** single/boolean AttrType, by definition of this. */
  final def attrType = SingleBooleanAttrType
  
  
  /** The generic form for this. */
  final val genericForm = new SingleAttributeGenericForm[Boolean] {
    def get(obj : TypedObject) : Boolean = obj.getBoolean(attr)
    
    def copy(src : TypedObject, tgt : MutableTypedObject) =
      tgt.setBoolean(attr, src.getBoolean(attr))
  }
  
}

/** An attribute single/int of the data model.
 */
trait SingleIntAttribute extends SingleAttribute[Int] {
  attr =>
  
  /** single/int AttrType, by definition of this. */
  final def attrType = SingleIntAttrType
  
  
  /** The generic form for this. */
  final val genericForm = new SingleAttributeGenericForm[Int] {
    def get(obj : TypedObject) : Int = obj.getInt(attr)
    
    def copy(src : TypedObject, tgt : MutableTypedObject) =
      tgt.setInt(attr, src.getInt(attr))
  }
  
}

/** An attribute single/string of the data model.
 */
trait SingleStringAttribute extends SingleAttribute[String] {
  attr =>
  
  /** single/string AttrType, by definition of this. */
  final def attrType = SingleStringAttrType
  
  
  /** The generic form for this. */
  final val genericForm = new SingleAttributeGenericForm[String] {
    def get(obj : TypedObject) : String = obj.getString(attr)
    
    def copy(src : TypedObject, tgt : MutableTypedObject) =
      tgt.setString(attr, src.getString(attr))
  }
  
}

/** An attribute single/id of the data model.
 */
trait SingleIdAttribute extends SingleAttribute[IDfId] {
  attr =>
  
  /** single/id AttrType, by definition of this. */
  final def attrType = SingleIdAttrType
  
  
  /** The generic form for this. */
  final val genericForm = new SingleAttributeGenericForm[IDfId] {
    def get(obj : TypedObject) : IDfId = obj.getId(attr)
    
    def copy(src : TypedObject, tgt : MutableTypedObject) =
      tgt.setId(attr, src.getId(attr))
  }
  
}

/** An attribute single/time of the data model.
 */
trait SingleTimeAttribute extends SingleAttribute[IDfTime] {
  attr =>
  
  /** single/time AttrType, by definition of this. */
  final def attrType = SingleTimeAttrType
  
  
  /** The generic form for this. */
  final val genericForm = new SingleAttributeGenericForm[IDfTime] {
    def get(obj : TypedObject) : IDfTime = obj.getTime(attr)
    
    def copy(src : TypedObject, tgt : MutableTypedObject) =
      tgt.setTime(attr, src.getTime(attr))
  }
  
}

/** An attribute single/double of the data model.
 */
trait SingleDoubleAttribute extends SingleAttribute[Double] {
  attr =>
  
  /** single/double AttrType, by definition of this. */
  final def attrType = SingleDoubleAttrType
  
  
  /** The generic form for this. */
  final val genericForm = new SingleAttributeGenericForm[Double] {
    def get(obj : TypedObject) : Double = obj.getDouble(attr)
    
    def copy(src : TypedObject, tgt : MutableTypedObject) =
      tgt.setDouble(attr, src.getDouble(attr))
  }
  
}